//************************************************************************
/// <copyrigth>2024-2025 Corporation.All Rights Reserved</copyrigth>
/// <author>tangyingzhong</author>
/// <contact>tangyz114987@outlook.com</contact>
/// <version>v1.0.0</version>
/// <describe>
/// Cross-Platform effective logger
///</describe>
/// <date>2024/5/15</date>
///***********************************************************************
#ifndef LOGGER_H
#define LOGGER_H

#include <atomic>
#include <string>
#include <mutex>
#include <memory>
#include "ModuleLoader/ModuleConfig.h"

namespace SystemTool
{
    class CLASS_ITEM Logger
    {
    public:  
        // Construct logger
        static Logger* GetInstance();

    private:
        // Construct the obj
        Logger();

        // Destruct the obj
        ~Logger();

        // Copy construct
        Logger(const Logger& other) = delete;

        // Assignment
        Logger& operator=(const Logger& other) = delete;

    public:
        // Add the logger
        void AddFileLogger(std::string strModuleName, std::string strLogFilePath);

        // Add the logger
        void AddConsoleLogger(std::string strModuleName);

        // Get logger
        std::shared_ptr<spdlog::logger> GetLogger(std::string strModuleName);

    private:
        // Init log cfg
        void InitCfg();

        // Log the msg
        void Log(std::string strModuleName, int iLevel, std::string strFilePath, int iLineNo, std::string strMsg);

    private:
        // Rotation size
        int m_iRotationSize = 0;

        // Cut off cnt
        int m_iCutoffCnt = 0;

        // Is open debug log
        bool m_bIsOpenDebugLog = false;

        // Is has inited
        std::atomic<bool> *m_pbIsInited = nullptr;
    };
}

#endif // LOGGER_H
